import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import QtQuick.Shapes 1.15

MainView {
    id: root
    width: 800
    height: 391
    property color btnColor: "#7080C0"
    property int btnHeight: 50
    property int btnWidth: 136
    property int txtWidth: 115
    signal loaderStart
    property bool normalSettingSaveOK:false
    function getZeroRange(){
        var lst=[];
        for(let i=0;i<100;i++){
            lst.push(i)
        }
        return lst
    }
    function getSaveDays(){
        var lst=[];
        for(let i=3;i<32;i++){
            lst.push(i)
        }
        return lst
    }
//    onVisibleChanged:
//    {
//        if(!visible)
//        {
//            destroy();
//        }
//    }
    Component.onDestruction: {
       funcTimer.destroy()
    }
    function isInteger(obj) {
     return (obj | 0) === obj
    }
function savePara()
{
    if(autoSave.currentIndex < 0
            ||saveDays.curentIndex < 0
            ||steadyStateRange.currentIndex < 0
            ||steadyStateFiltering.currentIndex < 0
            ||sampleRate.currentIndex < 0
            ||autoPowerZero.currentIndex < 0
            ||zeroRange.currentIndex < 0
            ||zeroTraceRange.currentIndex < 0
            ||backlight.currentIndex < 0
            ||screenSaveTime.currentIndex < 0){
        normalParaSaveOKDialog.title=qsTr("有选项未选中！")
        normalParaSaveOKDialog.open()
        normalParaSaveOKDialog.accepted.connect(function() {
                                normalParaSaveOKDialog.close()
                            })
        loaderText.visible=false
        return;
    }
    if(!isInteger(Number(collectTime.text))){
        normalParaSaveOKDialog.title=qsTr("采集时间必须是整数！")
        normalParaSaveOKDialog.open()
        normalParaSaveOKDialog.accepted.connect(function() {
                                normalParaSaveOKDialog.close()
                            })
        loaderText.visible=false
        return;
    }
    if(!isInteger(Number(interval.text))){
        normalParaSaveOKDialog.title=qsTr("保存间隔必须是整数！")
        normalParaSaveOKDialog.open()
        normalParaSaveOKDialog.accepted.connect(function() {
                                normalParaSaveOKDialog.close()
                            })
        loaderText.visible=false
        return;
    }

    var result = mymodbus.slotSaveNormalPara(Number(upperUpperLimit.text),Number(upperLimit.text),Number(lowerLimit.text),Number(lowerLowerLimit.text),Number(collectTime.text),Number(interval.text), Number(accumulateZero.text), autoSave.currentIndex,saveDays.currentValue,backlight.currentValue,screenSaveTime.currentValue)
    &&mymodbus.setStabilityRange(steadyStateRange.currentValue)
    &&mymodbus.setSteadyStateFiltering(steadyStateFiltering.currentValue)
    &&mymodbus.setADSampleRate(sampleRate.currentIndex)
    &&mymodbus.setPowerAutoZero(autoPowerZero.currentIndex)
    &&mymodbus.setClearRange(zeroRange.currentValue)
    &&mymodbus.setZeroTraceRange(zeroTraceRange.currentValue)




    loaderText.visible=false
    if(result){
        normalParaSaveOKDialog.title=qsTr("保存成功！")
        normalParaSaveOKDialog.open()
        normalParaSaveOKDialog.accepted.connect(function() {
                                normalParaSaveOKDialog.close()
                            })
    }
    else
    {
        normalParaSaveOKDialog.title=qsTr("保存失败！")
        normalParaSaveOKDialog.open()
        normalParaSaveOKDialog.accepted.connect(function() {
                                normalParaSaveOKDialog.close();
                            })
    }
}
    onLoaderStart: {
        mymodbus.getStabilityRange();
        mymodbus.getSteadyStateFiltering();
        mymodbus.getADSampleRate();
        mymodbus.getPowerAutoZero();
        mymodbus.getClearRange();
        mymodbus.getZeroTraceRange();
        mymodbus.getbacklight();

        //normalParaLoader.visible=true
        upperUpperLimit.text=mymodbus.upperUpperLimit
        upperLimit.text= mymodbus.upperLimit
        lowerLimit.text=mymodbus.lowerLimit
        lowerLowerLimit.text =mymodbus.lowerLowerLimit
        collectTime.text =mymodbus.collectTime
        interval.text = mymodbus.saveInterval
        accumulateZero.text = mymodbus.accumulateZero
        autoSave.currentIndex = mymodbus.autoSave
        saveDays.currentIndex = saveDays.find(mymodbus.saveDays)
        

        steadyStateRange.currentIndex = steadyStateRange.find(mymodbus.stabilityRange)
        steadyStateFiltering.currentIndex = steadyStateFiltering.find(mymodbus.steadyStateFiltering)
        sampleRate.currentIndex = mymodbus.aDSampleRate
        autoPowerZero.currentIndex = mymodbus.powerAutoZero
        zeroRange.currentIndex = zeroRange.find(mymodbus.clearRange)
        zeroTraceRange.currentIndex = zeroTraceRange.find(mymodbus.zeroTraceRange)
        backlight.currentIndex = backlight.find(mymodbus.backlight)
        screenSaveTime.currentIndex = screenSaveTime.find(mymodbus.screenSaveTime)
    }
    function onSteadyStateFiltering(){
        steadyStateFiltering.currentIndex = steadyStateFiltering.find(mymodbus.steadyStateFiltering)
        if(digitalFiltering.currentIndex>-1){
            normalParaLoader.visible=false
        }
    }
    function onDigitalFiltering(){
        digitalFiltering.currentIndex = digitalFiltering.find(mymodbus.digitalFiltering)
        if(steadyStateFiltering.currentIndex>-1){
            normalParaLoader.visible=false
        }
    }
    Component.onCompleted:
    {
        loaderStart()
    }

    Rectangle{
        id:mainRec
        width: 800
        height: 391
        visible:true
        color: "transparent"
        Rectangle
        {
            id:page0
            color:"transparent"
            width: 800
            height: 300
            visible: true
            GridLayout{
                id: normalSettingsLayout
                rows: 3
                columns: 6
                anchors.centerIn: parent
                rowSpacing: 40
                /*Button
                {
                    Layout.row:2
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("稳态滤波参数")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        steadyStateFiltering.popup.open()
                    }
                }
                MyComboBox
                {
                    id:steadyStateFiltering
                    Layout.row:2
                    Layout.column:1
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    model:[0,1,2,3,4,5,6,7,8,9]
                    currentIndex: steadyStateFiltering.find(mymodbus.steadyStateFiltering)
                }
                Button
                {
                    Layout.row:2
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("数字滤波参数")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        digitalFiltering.popup.open()
                    }
                }
                MyComboBox
                {
                    id:digitalFiltering
                    Layout.row:2
                    Layout.column:3
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    model:[0,1,2,3,4,5,6,7,8,9]
                    currentIndex: mymodbus.digitalFiltering
                }*/
                Button
                {
                    Layout.row:0
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("上上限")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                    }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=true;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel.itemName=qsTr("上上限")
                        enterNumberPanel.itemValue=upperUpperLimit.text
                        enterNumberPanel.textInput=upperUpperLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recUpperUpperLimit
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:0
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recUpperUpperLimit.height
                            PathLine {
                                x: recUpperUpperLimit.width
                                y: recUpperUpperLimit.height
                            }
                        }
                    }
                    TextInput{
                        id:upperUpperLimit
                        anchors.fill: parent
                        readOnly: true
                        //echoMode: TextInput.Password
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        text:""
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                enterNumberPanel.lastButtonIndex = 4;
                                enterNumberPanel.lastViewIndex =14;
                                enterNumberPanel._isNumber=true;
                                enterNumberPanel._isDecimal=true;
                                enterNumberPanel.itemName=qsTr("上上限")
                                enterNumberPanel.itemValue=upperUpperLimit.text
                                enterNumberPanel.textInput=upperUpperLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                enterNumberPanel.visible=true;
                                enterNumberPanel.lastRec=mainRec
                                mainRec.visible = false
                            }
                        }
                    }
                }
                Button
                {
                    Layout.row:0
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("上限")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=true;
                        enterNumberPanel.itemName=qsTr("上限")
                        enterNumberPanel.itemValue=upperLimit.text
                        enterNumberPanel.textInput=upperLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recUpperLimit
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:0
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recUpperLimit.height
                            PathLine {
                                x: recUpperLimit.width
                                y: recUpperLimit.height
                            }
                        }
                    }
                    TextInput{
                        id:upperLimit
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        text:""
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                enterNumberPanel.lastButtonIndex = 4;
                                enterNumberPanel.lastViewIndex =14;
                                enterNumberPanel._isNumber=true;
                                enterNumberPanel._isDecimal=true;
                                enterNumberPanel.itemName=qsTr("上限")
                                enterNumberPanel.itemValue=upperLimit.text
                                enterNumberPanel.textInput=upperLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                enterNumberPanel.visible=true;
                                enterNumberPanel.lastRec=mainRec
                                mainRec.visible = false
                            }
                        }
                    }
                }
                Button
                {
                    Layout.row:0
                    Layout.column:4
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("下限")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=true;
                        enterNumberPanel.itemName=qsTr("下限")
                        enterNumberPanel.itemValue=lowerLimit.text
                        enterNumberPanel.textInput=lowerLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recLowerLimit
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:0
                    Layout.column:5
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recLowerLimit.height
                            PathLine {
                                x: recLowerLimit.width
                                y: recLowerLimit.height
                            }
                        }
                    }
                    TextInput{
                        id:lowerLimit
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        text:""
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel._isNumber=true;
                                    enterNumberPanel._isDecimal=true;
                                    enterNumberPanel.itemName=qsTr("下限")
                                    enterNumberPanel.itemValue=lowerLimit.text
                                    enterNumberPanel.textInput=lowerLimit;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }

                    }
                }
                Button
                {
                    Layout.row:1
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("下下限")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=true;
                        enterNumberPanel.itemName=qsTr("下下限")
                        enterNumberPanel.itemValue=lowerLowerLimit.text
                        enterNumberPanel.textInput=lowerLowerLimit;
                        enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recLowerLowerLimit
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:1
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recLowerLowerLimit.height
                            PathLine {
                                x: recLowerLowerLimit.width
                                y: recLowerLowerLimit.height
                            }
                        }
                    }
                    TextInput{
                        id:lowerLowerLimit
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        text:""
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel._isNumber=true;
                                    enterNumberPanel._isDecimal=true;
                                    enterNumberPanel.itemName=qsTr("下下限")
                                    enterNumberPanel.itemValue=lowerLowerLimit.text
                                    enterNumberPanel.textInput=lowerLowerLimit;
                                    enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }

                    }
                }
                /*
                Button
                {
                    Layout.row:0
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("密码开关")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        pwdSwitch.popup.open()
                    }
                }
                MyComboBox
                {
                    id:pwdSwitch
                    Layout.row:0
                    Layout.column:1
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    model:[qsTr("关"),qsTr("开")]
                    currentIndex: -1
                }*/
                Button
                {
                    Layout.row:1
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("采集时间[ms]")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=false;
                        enterNumberPanel.itemName=qsTr("采集时间[ms]")
                        enterNumberPanel.itemValue=collectTime.text
                        enterNumberPanel.textInput=collectTime;
                        enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recCollectTime
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:1
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recCollectTime.height
                            PathLine {
                                x: recCollectTime.width
                                y: recCollectTime.height
                            }
                        }
                    }
                    TextInput{
                        id:collectTime
                        anchors.fill: parent
                        //echoMode: TextInput.Password
                        text:""
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel._isNumber=true;
                                    enterNumberPanel._isDecimal=false;
                                    enterNumberPanel.itemName=qsTr("采集时间[ms]")
                                    enterNumberPanel.itemValue=collectTime.text
                                    enterNumberPanel.textInput=collectTime;
                                    enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }

                    }
                }
                Button
                {
                    Layout.row:1
                    Layout.column:4
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("保存天数")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        saveDays.popup();
                    }
                }

                MyComboBox
                {
                    id:saveDays
                    Layout.row:1
                    Layout.column:5
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:getSaveDays()
                    //currentIndex: saveDays.find(mymodbus.saveDays)
                }

                Button
                {
                    Layout.row:2
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("定时保存")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        autoSave.popup();
                    }
                }

                MyComboBox
                {
                    id:autoSave
                    Layout.row:2
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[qsTr("关"),qsTr("开")]
                    currentIndex: mymodbus.autoSave
                }
                Button
                {

                    // x: 152
                    // y: 13
                    Layout.row:2
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    text: qsTr("保存间隔[s]")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=false;
                        enterNumberPanel.itemName=qsTr("保存间隔[s]")
                        enterNumberPanel.itemValue=interval.text
                        enterNumberPanel.textInput=interval;
                        enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recIntervial
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:2
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recIntervial.height
                            PathLine {
                                x: recIntervial.width
                                y: recIntervial.height
                            }
                        }
                    }
                    TextInput{
                        id:interval
                        anchors.fill: parent
                        //width:recWidth
                        //echoMode: TextInput.Password
                        text:mymodbus.saveInterval
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom

                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel._isNumber=true;
                                    enterNumberPanel._isDecimal=false;
                                    enterNumberPanel.itemName=qsTr("保存间隔[s]")
                                    enterNumberPanel.itemValue=interval.text
                                    enterNumberPanel.textInput=interval;
                                    enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }
                    }
                }
                Button
                {
                    Layout.row:2
                    Layout.column:4
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("累加零值")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel._isNumber=true;
                        enterNumberPanel._isDecimal=true;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel.itemName=qsTr("累加零值")
                        enterNumberPanel.itemValue=accumulateZero.text
                        enterNumberPanel.textInput=accumulateZero;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }

                Rectangle {
                    id: recAccumulateZero
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:2
                    Layout.column:5
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recAccumulateZero.height
                            PathLine {
                                x: recAccumulateZero.width
                                y: recAccumulateZero.height
                            }
                        }
                    }
                    TextInput{
                        id:accumulateZero
                        anchors.fill: parent
                        readOnly: true
                        //echoMode: TextInput.Password
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        text:""
                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel._isNumber=true;
                                    enterNumberPanel._isDecimal=true;
                                    enterNumberPanel.itemName=qsTr("累加零值")
                                    enterNumberPanel.itemValue=accumulateZero.text
                                    enterNumberPanel.textInput=accumulateZero;                                       enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }

                    }
                }
                /*
                Button
                {
                    Layout.row:0
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("校准阈值")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        enterNumberPanel.lastButtonIndex = 4;
                        enterNumberPanel.lastViewIndex =14;
                        enterNumberPanel.itemName=qsTr("校准阈值")
                        enterNumberPanel.itemValue=calThreshold.text
                        enterNumberPanel.textInput=calThreshold;
                        enterNumberPanel.lastViewUrl="NormalSettings.qml"
                        enterNumberPanel.maximum=100
                        enterNumberPanel.visible=true;
                        enterNumberPanel.lastRec=mainRec
                        mainRec.visible = false
                    }
                }
                Rectangle {
                    id: recCalThreshold
                    width:300
                    height:30
                    // x: 218
                    // y: 7
                    color: "transparent"
                    border.width: 0
                    border.color: "white"
                    Layout.row:0
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    // 绘制一条边框
                    Shape {
                        anchors.fill: parent
                        ShapePath {
                            strokeWidth: 3
                            strokeColor: "white"
                            strokeStyle: ShapePath.SolidLine
                            startX: 0
                            startY: recUpperUpperLimit.height
                            PathLine {
                                x: recUpperUpperLimit.width
                                y: recUpperUpperLimit.height
                            }
                        }
                    }
                    TextInput{
                        id:calThreshold
                        anchors.fill: parent
readOnly: true
                        //echoMode: TextInput.Password
                        color:"white"
                        font.pixelSize: 25
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        text:""
                        MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    enterNumberPanel.lastButtonIndex = 4;
                                    enterNumberPanel.lastViewIndex =14;
                                    enterNumberPanel.itemName=qsTr("校准阈值")
                                    enterNumberPanel.itemValue=calThreshold.text
                                    enterNumberPanel.textInput=calThreshold;
                                    enterNumberPanel.lastViewUrl="NormalSettings.qml"
                                    enterNumberPanel.maximum=100
                                    enterNumberPanel.visible=true;
                                    enterNumberPanel.lastRec=mainRec
                                    mainRec.visible = false
                                }
                            }
                    }
                }*/

            }

        }
        Rectangle
        {
            id:page1
            color:"transparent"
            width: 800
            height: 300
            visible: false
            GridLayout{
                id: advSettingsLayout
                rows: 3
                columns: 6
                anchors.centerIn: parent
                rowSpacing: 40
                Button
                {
                    Layout.row:0
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("判稳范围")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                        }
                    onClicked: {
                        steadyStateRange.popup.open()
                    }
                }
                MyComboBox
                {
                    id:steadyStateRange
                    Layout.row:0
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[1,2,3,4,5,6,7,8,9]
                    currentIndex: steadyStateRange.find(mymodbus.stabilityRange)
                }
                Button
                {
                    Layout.row:0
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("稳态滤波参数")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                    }
                    onClicked: {
                        steadyStateFiltering.popup.open()
                    }
                }
                MyComboBox
                {
                    id:steadyStateFiltering
                    Layout.row:0
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[0,1,2,3,4,5,6,7,8,9]
                    currentIndex: steadyStateFiltering.find(mymodbus.steadyStateFiltering)
                }
                Button
                {
                    Layout.row:0
                    Layout.column:4
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("AD采样速率")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        sampleRate.popup.open()
                    }
                }
                MyComboBox
                {
                    id:sampleRate
                    Layout.row:0
                    Layout.column:5
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:["10bps","40bps","640bps"]
                    currentIndex: mymodbus.aDSampleRate
                }
                Button
                {
                    Layout.row:1
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("上电自动清零")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        autoPowerZero.popup.open()
                    }
                }
                MyComboBox
                {
                    id:autoPowerZero
                    Layout.row:1
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:["关","开"]
                    currentIndex: mymodbus.powerAutoZero
                }
                Button
                {
                    Layout.row:1
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("开机置零范围")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                            }
                    onClicked: {
                        zeroRange.popup.open()
                    }
                }
                MyComboBox
                {
                    id:zeroRange
                    Layout.row:1
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:getZeroRange()
                    currentIndex: zeroRange.find(mymodbus.clearRange)
                }
                Button
                {
                    Layout.row:1
                    Layout.column:4
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("零点跟踪范围")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                    }
                    onClicked: {
                        zeroTraceRange.popup.open()
                    }
                }
                MyComboBox
                {
                    id:zeroTraceRange
                    Layout.row:1
                    Layout.column:5
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[0,1,2,3,4,5,6,7,8,9]
                    currentIndex: zeroTraceRange.find(mymodbus.zeroTraceRange)
                }
                Button
                {
                    Layout.row:2
                    Layout.column:0
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("背光强度")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                    }
                    onClicked: {
                        backlight.popup.open()
                    }
                }
                MyComboBox
                {
                    id:backlight
                    Layout.row:2
                    Layout.column:1
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[1,2,3,4,5,6,7,8,9]
                    currentIndex: backlight.find(mymodbus.backlight)
                }
                Button
                {
                    Layout.row:2
                    Layout.column:2
                    Layout.preferredWidth: btnWidth
                    Layout.preferredHeight: btnHeight
                    // x: 152
                    // y: 13
                    text: qsTr("屏幕保护时间")
                    font.pixelSize: 18
                    background: Rectangle{
                        color: btnColor
                    }
                    onClicked: {
                        screenSaveTime.popup.open()
                    }
                }
                MyComboBox
                {
                    id:screenSaveTime
                    Layout.row:2
                    Layout.column:3
                    Layout.preferredWidth: txtWidth
                    Layout.preferredHeight: btnHeight
                    model:[0,30,60,90,120,150,180,210,240,270,300]
                    currentIndex: screenSaveTime.find(mymodbus.screenSaveTime)
                }
            }

        }

        Row {
            x:57
            y:320
            Button {
                id: btnPrePage
                height: 40
                width: 123
                text: qsTr("上一页")
                font.pixelSize: 25
                palette.buttonText: "white"
                onClicked: {
                    page0.visible=true
                    page1.visible=false
                    pageNo.text="1/2"
                }
                background: Rectangle {
                    color: "#7584c2"
                    border.width: 0
                }
            }

            Text{
                id:pageNo
                font.pixelSize: 38
                height:40
                color:"White"
                text:"1/2"
            }

            Button {
                id: btnNextPage
                height: 40
                width: 123
                text: qsTr("下一页")
                font.pixelSize: 25
                palette.buttonText: "white"
                onClicked: {
                    page1.visible=true
                    page0.visible=false
                    pageNo.text="2/2"
                }
                background: Rectangle {
                    color: "#7584c2"
                    border.width: 0
                }
            }
        }

        Button
        {
            id:btnNormalParaOK
            x: 572
            y: 281
            //x: 675
            //y: 20
            width: 100
            height: 100
            background: Rectangle{
                border.width: 0
                color: "#C070B0"
                    }

            text: qsTr("确定")
            font.pixelSize: 25
            palette.buttonText: "white"
            Connections {
                target: btnNormalParaOK
                function onClicked() {
                    if(loaderText.visible)
                    {
                        return;
                    }
                    loaderText.visible=true;
                    funcTimer.start();
                }
            }
        }
       Button
        {
            id:btnReturn
            x: 688
            y: 281
            //x: 675
            //y: 20
            width: 100
            height: 100
            background: Rectangle{
                border.width: 0
                color: "#B0B0D0"
                    }

            text: qsTr("返回")
            font.pixelSize: 25
            palette.buttonText: "white"
            onClicked: {
                //rectangle.selectedView = 4
                bottomBar.selected=4
//                myLoader.visible=false;
//                myLoader.visible=true
                myLoader.source="SettingsPanel.qml"
                //destroy()
            }
        }

    }

    Timer{
       id:nsTimmer
       interval: 1000
       running: false
       repeat: false
       onTriggered: {
//           minGraduation.currentIndex = minGraduation.find(mymodbus.minGraduation)
//           decimalPlaces.currentIndex = decimalPlaces.find(mymodbus.decimalPlaces)
//           unit.currentIndex = unit.find(mymodbus.unit)
//           steadyStateFiltering.currentIndex = steadyStateFiltering.find(mymodbus.steadyStateFiltering)
//           digitalFiltering.currentIndex = digitalFiltering.find(mymodbus.digitalFiltering)
           upperUpperLimit.text=mymodbus.upperUpperLimit
           upperLimit.text= mymodbus.upperLimit
           lowerLimit.text=mymodbus.lowerLimit
           lowerLowerLimit.text =mymodbus.lowerLowerLimit
           //pwdSwitch.currentIndex= mytables.pwdSwitch
           collectTime.text =mymodbus.collectTime
           normalParaLoader.visible = false
       }
   }
    Timer {
        id:funcTimer
                running: false
                repeat: false
                interval:100
                onTriggered: {
                    savePara()
                }
            }

    EnterNumberPanel{
          id:enterNumberPanel
          width: 800
          height: 391
          visible:false
    }
   MyBuzyIndicator{
       anchors.centerIn: parent
       id: normalParaLoader
       visible:false
       z:101
   }
   Dialog {
       anchors.centerIn: parent
       id: normalParaSaveOKDialog
       //title: "提示"
       standardButtons: Dialog.Ok
       title:qsTr("保存成功！")
       modal:true
       closePolicy: "CloseOnEscape"
       onAccepted: {
           normalParaSaveOKDialog.close()
           if(normalSettingSaveOK){
               //rectangle.selectedView = 0;
               bottomBar.selected = 0;
               //myLoader.setsource = "StatusView.qml"
               //myLoader.visible=false;
               //statusView.visible=true;
               //myLoader.visible=false;
               //myLoader.visible=true;
               myLoader.source="StatusView.qml"
           }

       }
       z:100
       //onRejected: console.log("Cancel clicked")
   }
}